﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model.enumer;

namespace com.lover.astd.common.logicexe.activities
{
    public class KfBanquetExe : ExeBase
    {
        public KfBanquetExe() { _name = ConfigStrings.S_KfBanquet; _readable = ConfigStrings.SR_KfBanquet; }
        public override long execute()
        {
            if (!_user.isActivityRunning(ActivityType.KfBanquet)) return next_hour();

            Dictionary<string, string> conf = getConfig();
            if (!conf.ContainsKey(ConfigStrings.enabled) || !conf[ConfigStrings.enabled].ToLower().Equals("true")) return an_hour_later();
            bool do_single = conf.ContainsKey(ConfigStrings.single) && conf[ConfigStrings.single].ToLower().Equals("true");
            int conf_buygold = 0;
            if (conf.ContainsKey(ConfigStrings.buygold)) Int32.TryParse(conf[ConfigStrings.buygold], out conf_buygold);
            ActivityMgr mgr = ServiceFactory.getActivityManager();

            long cdMSeconds = 0;
            int result = mgr.handleKfBanquetInfo(_proto, _logger, _user, conf_buygold, !do_single, getGoldAvailable(), out cdMSeconds);
            if (result == 1) return next_hour();
            if (result == 10) return next_day();

            if (cdMSeconds > 0) return cdMSeconds;
            return next_hour();
        }
    }
}
